java无法单击使用Selenium WebDriver创建的<div>下拉列表
HTML代码
<div qxselectable="off" >
<div qxselectable="off" >
<div tabindex="1" qxselectable="off" >
<div tabindex="1" qxselectable="off" >
<div style="overflow: hidden; >Discrepancy Type*</div>
<div class="qx-input-required" tabindex="7" ">
<input class="qx-abstract-field qx-placeholder-color" >
//On Below button there is one dropdown button on which i want to click but i cannot
<div class="qx-button" qxselectable="off" >
<div qxselectable="off" qxanonymous="true" ></div>
</div>
</div>
</div>
<div tabindex="1" qxselectable="off" >
</div>
</div>
<div class="qx-outSet" qxse..
Java代码
WebElement element = wd.findElement(By.className("qx-input-required"));
Actions actions = new Actions(wd);
actions.moveToElement(element).click().perform();
wd.findElement(By.xpath(".//*[@id='demindoRoot']/div[3]/div[2]/div[1]/div/div[2]/div[2]/div/div")).click(); // link through which i try to click
Thread.sleep(1000);
我还尝试了下面提到的代码
wd.findElement(By.xpath("//div[@class='qx-button'"));
错误:
Unable to locate element:
# 1 楼答案
xpath应该是您的下拉框,而不是您的下拉值
# 2 楼答案
这会像用户那样执行操作。用户首先导航到菜单,打开它,然后导航到要单击的元素。查看此问题了解更多详细信息: https://stackoverflow.com/a/17294390/3537915
# 3 楼答案
基本上,当我们使用任何使用javascript开发的任何Web应用程序时,我们无法获得任何适当的元素进行交互。 我们必须和很多人一起工作。 因此,在从下拉列表中选择任何值时,我们必须使用sendkeys。 或者简单地键入单个字符,然后从建议列表中选择值。 以上两个解决方案对我来说很有效
谢谢 -达瓦尔